<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
   <%@page import="it.polimi.travelDream.ejb.servlet.*" %>
   <%@page import="it.polimi.travelDream.entities.*" %>
      <%@page import="it.polimi.travelDream.entities.Package" %>
   
  	<jsp:useBean id="tlmgr" class="it.polimi.travelDream.ejb.beans.TravelListMgr" scope="session" />
  	 <jsp:useBean id="ppmgr" class="it.polimi.travelDream.ejb.beans.PersonalizedMgr" scope="session" />
  	 <jsp:useBean id="pmgr" class="it.polimi.travelDream.ejb.beans.PackageMgr" scope="session" />
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>
		  	TravelDreamLogin
		  	
		</title>
		<link rel="stylesheet" type="text/css" href="style.css" />
  	</head>
  
  <body>
  	<div class="header">
  		<ul>
	  		<li>TravelDream</li>
		    Travel List
	    </ul>
  	</div>
 
  	<div class="section">
  	 
	    <div class="nav">
	    	<ul>
	    		<li> <a href="UHome.jsp">Home</a></li>
	    		<li> <a href="USearch.jsp">Search packages</a></li>
	    			<% if (request.getSession().getAttribute("utente")!=null )
		    	{ User z=(User)request.getSession().getAttribute("utente");
		    	out.println("<li class=cur><a href=/TravelDreamSystemWeb/ShowTravelList?travellistowner="+z.getId()+" >Travel List </a></li>"); 
		    	} %>
	    			 
	    		<% if (request.getSession().getAttribute("utente")!=null )
		    	{ User z=(User)request.getSession().getAttribute("utente");
		    	out.println("<li><a href=/TravelDreamSystemWeb/ShowWishList?wishlistowner="+z.getId()+" >Wish List </a></li>"); 
		    	} %>
	    		<li> <a href="UCart.jsp">Cart</a></li>
	    		<li><a href="SendMail.jsp">Invite To WishList</a></li>
	    		<li> <a href="SendMail2.jsp"> Invite to TravelList </a></li>
	    			<li> <a href="/TravelDreamSystemWeb/LogoutServlet?session=0"> Logout </a></li>
	    	</ul>
	    </div>
	    
	    <div class="content">
	      <% 
	      if (request.getSession().getAttribute("utente")!=null )
		    	{ User z=(User)request.getSession().getAttribute("utente");
		    		System.out.println("ciao"+z.getId()+request.getParameter("travellistowner"));
		    	
	    
		  %>
	    
	    	<%  
	    
        		int i = tlmgr.ShowAllTravelList(Integer.parseInt(request.getParameter("travellistowner"))).size() - 1;
	    		int userid = -1;
    	  		if (request.getSession().getAttribute("utente")!=null )
   		    	{ User u=(User)request.getSession().getAttribute("utente");
   		    	userid = u.getId(); 
   		    	}
	    		
        		while (i>=0) {
        			Modified_Package pp = tlmgr.ShowAllTravelList(Integer.parseInt(request.getParameter("travellistowner"))).get(i).getIdPackage();
        			out.println("<div class=record>") ;
        			
        			out.println("<div class=recordfield>") ;
        			out.println("<input class=fakeinput readonly=readonly type=text value="+pp.getNative_id().getName()+" name=name />");
        			out.println("</div>");
        			
        			if ( userid != Integer.parseInt(request.getParameter("travellistowner")))
        			{
            			out.println("<form action=JoinTravelList method=POST >") ;
            			out.println("<input type=hidden value="+pp.getId()+" name=idPersonalizedPackage />");
            			out.println("<input type=hidden value="+z.getEmail()+" name=UserEmail />");
            			out.println("<input type=hidden value="+ tlmgr.ShowAllTravelList(Integer.parseInt(request.getParameter("travellistowner"))).get(i).getIdTl() +" name=idTravelList />");
            			out.println("<input class=fakebutton type=submit value=Join />");
            			out.println("</form>");
        			}
        			else
        			{
        			out.println("<form action=DelTravelList method=POST >") ;
        			out.println("<input type=hidden value="+pp.getId()+" name=idPersonalizedPackage />");
        			out.println("<input type=hidden value="+request.getParameter("travellistowner")+" name=idUser />");
        			out.println("<input type=hidden value="+ tlmgr.ShowAllTravelList(z.getId()).get(i).getIdTl() +" name=idTravelList />");
        			out.println("<input class=fakebutton type=submit value=Del />");
        			out.println("</form>");

        	
        			out.println("<form action=AddPPackageToCart method=POST >") ;
        			out.println("<input type=hidden value="+pp.getId()+" name=idPersonalizedPackage />");
        			out.println("<input type=hidden value="+request.getParameter("travellistowner")+" name=idUser />");
        			out.println("<input type=hidden value="+tlmgr.ShowAllTravelList(z.getId()).get(i).getIdTl()+" name=idTravelList />");
        			out.println("<input class=fakebutton type=submit value=ToCart />");
        			out.println("</form>");

        			
        			

        			out.println("<form action=AddPPackageToGiftList method=POST >") ;
        			out.println("<input type=hidden value="+pp.getId()+" name=idPersonalizedPackage />");
        			out.println("<input type=hidden value="+request.getParameter("travellistowner")+" name=idUser />");
        			out.println("<input type=hidden value="+ tlmgr.ShowAllTravelList(z.getId()).get(i).getIdTl() +" name=idTravelList />");
        			out.println("<input class=fakebutton type=submit value=ToGiftList />");
        			out.println("</form>");
        			}
        			
        			out.println("</div>");
        			i--;
	    			
        			
        		}
    		%>
		
    			   <% 
	    	if (request.getAttribute("message") == null) 
		    	{ 
		    		%>
						<div></div>
					<% 
				} 
	    	else 
		    	{ 
		    		%>
						<div class="advice"><%=request.getAttribute("message")%></div>
					<% 
				} 
		%>
		</div>
<%
		} else { 
				response.sendRedirect("/TravelDreamSystemWeb/login.jsp");
				%>
				
				
					<%
				}
		%>
    </div>
    
    <div class="footer">
    	<ul>
	    	<li>TravelDream Company srl © All rights reserved</li>
		    <li>Terms of use | Contacts | Team </li>
	    </ul>
    </div>
    
  </body>
</html>